﻿using System;

namespace cz.zcu.PreSti.Components
{
    public class UniformDistributionGenerator : BaseComponent
    {
        private Random r;
        private double startInterval = 0;
        private double endInterval = 1;

        #region properties

        public double StartInterval
        {
            set
            {
                startInterval = value;
            }
            get
            {
                return startInterval;
            }
        }

        public double EndInterval
        {
            set
            {
                endInterval = value;
            }
            get
            {
                return endInterval;
            }
        }

        #endregion

        public UniformDistributionGenerator() : base(0, 1) 
        {
            r = new Random(this.GetHashCode()); //bug 6911: constructor without parameter makes all generators not really random
        }

        public override object getValueFromGetter(int getterN)
        {
            switch (getterN)
            {
                case 0:
                    return r.NextDouble() * (endInterval - startInterval) + startInterval;
            }
            return base.getValueFromGetter(getterN);
        }
    }
}
